from selenium import webdriver
from time import sleep,ctime
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get("http://www.baidu.com")
# element = WebDriverWait(driver,5,0.5).until(        #（浏览器驱动，最长等待时间（s），检测时间的步长，iqnored_exceptions=None(超时情况下抛出的异常)）
#     EC.visibility_of_element_located((By.ID,"kw"))
# )
# element.send_keys("selenium")
#
# sleep(5)
# driver.quit()
#2
print(ctime())
for i in range(10):                           #实现元素的显示等待
    try:
        el = driver.find_element_by_id("kw22")
        if el.is_displayed():        #is_displayed()判断元素是否可见
            break
    except:
        pass
    sleep(1)
else:
    print("time out")
print(ctime())
driver.quit()

